package cn.yunhe.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class NewsDao {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;

	public List<String> queryNewsByTitle(String keyword) {
		List<String> titles = new ArrayList<String>();
		try {
			conn = DaoFacotry.getConn();
			String sql = "select news_title from t_news where news_title like ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "%" + keyword + "%");
			rs = pstmt.executeQuery();

			while (rs.next()) {
				String title = rs.getString(1);
				titles.add(title);
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DaoFacotry.closeAll(conn, pstmt, rs);
		}
		return titles;
	}
}
